#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 4005;

int a[9][9], b[9][9];
int n, m;
int cnt;
int row[N], col[N];
int l[N], r[N], u[N], d[N];
int h[N], s[N];
int ans[N];
void init() {
  rep(i, 0, m) u[i] = d[i] = i, l[i] = i - 1, r[i] = i + 1;
  l[0] = m, r[m] = 0;
  cnt = m;
}
void link(int x, int y) {
  ++cnt, s[y]++;
  row[cnt] = x, col[cnt] = y;
  // 插入到列链表中
  d[u[y]] = cnt;
  u[cnt] = u[y];
  u[y] = cnt;
  d[cnt] = y;
  // 插入到行链表中
  if (!h[x]) {
    h[x] = l[cnt] = r[cnt] = cnt;
  } else {
    r[l[h[x]]] = cnt;
    l[cnt] = l[h[x]];
    l[h[x]] = cnt;
    r[cnt] = h[x];
  }
}

void remove(int y) {
  r[l[y]] = r[y];
  l[r[y]] = l[y];
  for (int i = d[y]; i != y; i = d[i]) {
    for (int j = r[i]; j != i; j = r[j]) {
      d[u[j]] = d[j];
      u[d[j]] = u[j];
      s[col[j]]--;
    }
  }
}
void resume(int y) {
  r[l[y]] = y;
  l[r[y]] = y;
  for (int i = d[y]; i != y; i = d[i]) {
    for (int j = r[i]; j != i; j = r[j]) {
      d[u[j]] = j;
      u[d[j]] = j;
      s[col[j]]++;
    }
  }
}

int mx_scores = -1;
void dance(int dep) {
  if (!r[0]) {
    rep(i, 1, dep) {
      int j = ans[i];
      int x = (ans[i] - 1) / 81, y = (ans[i] - 1) / 9 % 9;
      int z = (ans[i] - 1) % 9 + 1;
      a[x][y] = z;
    }
    int scores = 0;
    rep(i, 0, 8) rep(j, 0, 8) scores += a[i][j] * b[i][j];
    mx_scores = max(mx_scores, scores);
    return;
  }
  int y = r[0];
  for (int j = r[0]; j; j = r[j])
    if (s[j] < s[y]) y = j;
  remove(y);
  for (int i = d[y]; i != y; i = d[i]) {
    ans[dep + 1] = row[i];
    for (int j = r[i]; j != i; j = r[j]) remove(col[j]);
    dance(dep + 1);
    // 注意这里的逆序还原，对性能影响极大
    for (int j = l[i]; j != i; j = l[j]) resume(col[j]);
  }
  resume(y);
}

void build() {
  rep(i, 0, 8) rep(j, 0, 8) rep(k, 1, 9) {
    if (a[i][j] == 0 || a[i][j] == k) {
      int r = i * 81 + j * 9 + k;
      link(r, i * 9 + j + 1);
      link(r, 81 + i * 9 + k);
      link(r, 81 * 2 + j * 9 + k);
      link(r, 81 * 3 + (i / 3 * 3 + j / 3) * 9 + k);
    }
  }
}
void init_scores() {
  rep(i, 0, 8) rep(j, 0, 8) b[i][j] = min({i, 8 - i, j, 8 - j}) + 6;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init_scores();
  n = 729, m = 324;
  init();
  rep(i, 0, 8) rep(j, 0, 8) cin >> a[i][j];
  build();
  dance(0);
  cout << mx_scores;
  return 0;
}